package com.management.department.teacherinfosystem.Entity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "activities")
@Getter
@Setter
@JsonIgnoreProperties({"user","reviewer","attachments"})
public class Activity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    // 活动基本信息
    @Column(name = "activity_name", nullable = false, length = 255)
    private String activityName; // 活动名称

    @Column(name = "activity_type", nullable = false, length = 100)
    private String activityType; // 活动类型（学术会议、教学研讨会、培训、考察交流、竞赛评审等）

    @Column(name = "organizer", nullable = false, length = 255)
    private String organizer; // 主办单位

    @Column(name = "organizer_level", length = 100)
    private String organizerLevel; // 主办单位级别（校级/省部级/国家级/国际）

    @Column(name = "location", nullable = false, length = 500)
    private String location; // 活动地点（线上/线下+具体地点）

    // 参与信息
    @Column(name = "start_date", nullable = false)
    private LocalDate startDate; // 活动起止日期

    @Column(name = "end_date", nullable = false)
    private LocalDate endDate;

    @Column(name = "participant_name", nullable = false, length = 100)
    private String participantName; // 参与人姓名

    @Column(name = "participant_role", nullable = false, length = 100)
    private String participantRole; // 参与角色（组织者、主持人、报告人/发言、参会代表、评委等）

    @Column(name = "has_report", nullable = false)
    private Boolean hasReport; // 是否做报告（是/否）

    @Column(name = "report_title", length = 500)
    private String reportTitle; // 报告题目（若做报告）

    // 申请人信息
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @JsonIgnore
    private User user;

    // 审核状态
    @Column(name = "status", nullable = false, length = 20)
    private String status = "PENDING"; // PENDING, APPROVED, REJECTED

    @Column(name = "review_comment", length = 500)
    private String reviewComment; // 审核意见

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reviewer_id")
    @JsonIgnore
    private User reviewer; // 审核人

    @Column(name = "review_time")
    private LocalDateTime reviewTime; // 审核时间

    // 证明材料
    @OneToMany(mappedBy = "activity", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonIgnore
    private List<ActivityAttachment> attachments;

    // 时间戳
    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt = LocalDateTime.now();

    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt = LocalDateTime.now();

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
} 